package com.dingwei.lesyndrome.mvp.presenter;

import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.NewsListBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class NewsFragmentPresenter extends basePresenter {

    private Contract.NewsFragmentView newsFragmentView;

    public NewsFragmentPresenter(Contract.NewsFragmentView view) {
        super(view);
        this.newsFragmentView = view;
    }

    public void initData(int cpage, String cid, final boolean isRefresh, boolean isShowDialog) {
        RequestParams rp = new RequestParams(URLS.HOST+URLS.NEWS_LIST);
        rp.addBodyParameter("cpage", cpage+"");
        rp.addBodyParameter("cid", cid);
        x.http().post(rp, new myCallback(BaseActivity.context, NewsListBean.class,isShowDialog, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                NewsListBean bean = (NewsListBean) baseBean;
                if (isRefresh){
                    newsFragmentView.onRefresh(bean);
                }else {
                    newsFragmentView.onLoadMore(bean);
                }
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                newsFragmentView.onFail();
            }
        });
    }

}
